/*
day133_2
2020.1.8
*/
#include<vector>
#include<iostream>
using namespace std;

class Solution {
public:
    int largestPerimeter(vector<int>& A) {
        for(int i=A.size()/2-1;i>=0;i--)
        {
        	filt(A,i,0,A.size()-1);
		}
		return 0;
    }
    
    void filt(vector<int>& A,int root,int beg,int end)
    {
    	int left=root*2+1;
		int right=left+1; 
		int max=A[root];
		
		
		int l,r;
		
		
		if(left<=end)	l=A[left];
		else	l=INT_MIN;
		
		if(right<=end)	r=A[right];
		else	r=INT_MIN;
		
		
		max = max >= l ? max : l;
		max = max >= r ? max : r;
		
		if(max==A[root]) return;
		
		else if(max==l)
		{
			A[left] = A[root];
			A[root] = max;
			filt(A,left,beg,end);
			
		}
		
		else
		{
			A[right] = A[root];
			A[root] = max;
			filt(A,right,beg,end);
		}
		
	}
};



int main()
{
	vector<int> vec={2,1,2};
	Solution s;
	s.largestPerimeter(vec);
	for(int i=0;i<vec.size();i++)
	{
		cout<<vec[i]<<endl;
	 } 
	return 0;
}
